
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:qr_flutter/qr_flutter.dart';
import 'package:xin_he/utils/xh_styles.dart';
import 'package:xin_he/utils/xin_he_toast.dart';

import '../../../utils/xin_he_image.dart';
import '../../../utils/xin_he_user_data.dart';
import 'xin_he_invite_friend_logic.dart';

class XinHeInviteFriendPage extends StatelessWidget {
  XinHeInviteFriendPage({Key? key}) : super(key: key);

  final logic = Get.put(XinHeInviteFriendLogic());
  final state = Get.find<XinHeInviteFriendLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        leading: IconButton(
            onPressed: (){
              Get.back();
            },
            icon: Container(
              padding: EdgeInsets.only(left: 7),
              alignment: Alignment.centerLeft,
              child: const XinHeAssetImage(
                'assets/images/home/app_back_3.png',
                width: 9.5,
                height: 17,
                fit: BoxFit.cover,),
            )
        ),
        title: const Text('邀请好友',style: TextStyle(color: Colors.black , fontSize: 18,fontWeight: FontWeight.w600),),
        backgroundColor: Colors.white,
        shadowColor: Colors.transparent,
      ) ,
      body: Column(
        children: [
       RepaintBoundary(
         key: logic.globalKey,
         child: Stack(children: [
           XinHeAssetImage('assets/images/mine/share_bg.png',width: Get.width,height: Get.width*500/375,fit: BoxFit.fill,),
           Positioned(
             top: 81*Get.width/275,
               left: (Get.width-81)*0.5,
               child: QrImageView(data: xinHeUserData.userDetailInfo.value?.code??'',size: 81,backgroundColor: Colors.white,)
           ),

           Positioned(
             top: 81*Get.width/275+81+12,
               left: (Get.width-233)*0.5,
               child: Column(
                 crossAxisAlignment: CrossAxisAlignment.center,
                 children: [
                 const Text('我的邀请码',style: TextStyle(color: Colors.white,fontSize: 13,fontWeight: FontWeight.bold),),
                 const SizedBox(height: 5,),
                 Container(
                   height: 33,
                   width: 233,
                   decoration: BoxDecoration(color: XinHeColor('#8CCFB7'),borderRadius: BorderRadius.circular(5) ),
                   child: Row(children: [
                     const SizedBox(width: 16,),
                     Text(state.inviteCode.value,style: TextStyle(color: XinHeColor('#222222'),fontSize: 15,fontWeight: FontWeight.bold),),
                     const Spacer(),
                     GestureDetector(
                       onTap: (){
                         Clipboard.setData(  ClipboardData(text: state.inviteCode.value));
                         XinHeToast.center('复制邀请码成功');
                       },
                       child: Container(
                         height: 21,
                         width: 50,
                         alignment: Alignment.center,
                         decoration: BoxDecoration(color: XinHeColor('#1F8768'),borderRadius: BorderRadius.circular(10.5)),
                         child: Text('复制',style: TextStyle(color: XinHeColor('#FFFFFF'),fontSize: 12,fontWeight: FontWeight.w500),strutStyle: const StrutStyle(forceStrutHeight: true),),),
                     ),
                     const SizedBox(width: 10,)

                   ],),
                 )
               ],)
           )
         ],),
       ),
        Container(
          height: 94,
          alignment: Alignment.center,
          child: Row(
            mainAxisSize: MainAxisSize.min,
            children: [
            Container(
              height: 37,
              width: 115,
              alignment: Alignment.center,
              decoration: BoxDecoration(color: Colors.white,borderRadius: BorderRadius.circular(18.5),border: Border.all(color: XinHeColor('#1F8768'),width: 0.5)),
              child: Text('分享',style: TextStyle(color: XinHeColor('#1F8768'),fontSize: 15,fontWeight: FontWeight.bold),),
            ),
            const SizedBox(width:14 ,),
            GestureDetector(
              onTap: (){
                  logic.saveScreenshot();
              },
              child: Container(
                height: 37,
                width: 115,
                alignment: Alignment.center,
                decoration: BoxDecoration(color:  XinHeColor('#1F8768'),borderRadius: BorderRadius.circular(18.5)),
                child: const Text('保存',style: TextStyle(color: Colors.white,fontSize: 15,fontWeight: FontWeight.bold),),
              ),
            ),
          ],),
        ),
        SizedBox(height: Get.mediaQuery.padding.bottom,),

      ],),

    );
  }




}
